home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / tcsh / dist / sh.char.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-21  |  4.6 KB  |  106 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.01/RCS/sh.char.h,v 3.1 1991/11/26 04:41:23 christos Exp $ */
  2. /*
  3.  * sh.char.h: Table for spotting special characters quickly
  4.  *           Makes for very obscure but efficient coding.
  5.  */
  6. /*-
  7.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38. #ifndef _h_sh_char
  39. #define _h_sh_char
  40. #include <ctype.h>
  41.  
  42. #ifdef _MINIX
  43. # undef _SP
  44. #endif /* _MINIX */
  45. extern unsigned short _cmap[];
  46.  
  47. #ifndef NLS
  48. extern unsigned char _cmap_lower[], _cmap_upper[];
  49.  
  50. #endif
  51.  
  52. #define    _Q    0x0001        /* '" */
  53. #define    _Q1    0x0002        /* ` */
  54. #define    _SP    0x0004        /* space and tab */
  55. #define    _NL    0x0008        /* \n */
  56. #define    _META    0x0010        /* lex meta characters, sp #'`";&<>()|\t\n */
  57. #define    _GLOB    0x0020        /* glob characters, *?{[` */
  58. #define    _ESC    0x0040        /* \ */
  59. #define    _DOL    0x0080        /* $ */
  60. #define    _DIG      0x0100        /* 0-9 */
  61. #define    _LET      0x0200        /* a-z, A-Z, _ */
  62. #define    _UP       0x0400        /* A-Z */
  63. #define    _LOW      0x0800        /* a-z */
  64. #define    _XD     0x1000        /* 0-9, a-f, A-F */
  65. #define    _CMD    0x2000        /* lex end of command chars, ;&(|` */
  66. #define _CTR    0x4000        /* control */
  67.  
  68. #define cmap(c, bits)    \
  69.     (((c) & QUOTE) ? 0 : (_cmap[(unsigned char)(c)] & (bits)))
  70.  
  71. #define isglob(c)    cmap(c, _GLOB)
  72. #define isspc(c)    cmap(c, _SP)
  73. #define ismeta(c)    cmap(c, _META)
  74. #define iscmdmeta(c)    cmap(c, _CMD)
  75. #define letter(c)    (((c) & QUOTE) ? 0 : \
  76.              (isalpha((unsigned char) (c)) || (c) == '_'))
  77. #define alnum(c)    (((c) & QUOTE) ? 0 : \
  78.                  (isalnum((unsigned char) (c)) || (c) == '_'))
  79. #ifdef NLS
  80. # define Isspace(c)    (((c) & QUOTE) ? 0 : isspace((unsigned char) (c)))
  81. # define Isdigit(c)    (((c) & QUOTE) ? 0 : isdigit((unsigned char) (c)))
  82. # define Isalpha(c)    (((c) & QUOTE) ? 0 : isalpha((unsigned char) (c)))
  83. # define Islower(c)    (((c) & QUOTE) ? 0 : islower((unsigned char) (c)))
  84. # define Isupper(c)    (((c) & QUOTE) ? 0 : isupper((unsigned char) (c)))
  85. # define Tolower(c)     (((c) & QUOTE) ? 0 : tolower((unsigned char) (c)))
  86. # define Toupper(c)     (((c) & QUOTE) ? 0 : toupper((unsigned char) (c)))
  87. # define Isxdigit(c)    (((c) & QUOTE) ? 0 : isxdigit((unsigned char) (c)))
  88. # define Isalnum(c)    (((c) & QUOTE) ? 0 : isalnum((unsigned char) (c)))
  89. # define Iscntrl(c)     (((c) & QUOTE) ? 0 : iscntrl((unsigned char) (c)))
  90. # define Isprint(c)     (((c) & QUOTE) ? 0 : isprint((unsigned char) (c)))
  91. #else
  92. # define Isspace(c)    cmap(c, _SP|_NL)
  93. # define Isdigit(c)    cmap(c, _DIG)
  94. # define Isalpha(c)    (cmap(c,_LET) && !(((c) & META) && AsciiOnly))
  95. # define Islower(c)    (cmap(c,_LOW) && !(((c) & META) && AsciiOnly))
  96. # define Isupper(c)    (cmap(c, _UP) && !(((c) & META) && AsciiOnly))
  97. # define Tolower(c)    (_cmap_lower[(unsigned char)(c)])
  98. # define Toupper(c)    (_cmap_upper[(unsigned char)(c)])
  99. # define Isxdigit(c)    cmap(c, _XD)
  100. # define Isalnum(c)    (cmap(c, _DIG|_LET) && !(((c) & META) && AsciiOnly))
  101. # define Iscntrl(c)    (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
  102. # define Isprint(c)    (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
  103. #endif
  104.  
  105. #endif /* _h_sh_char */
  106.